package pailaidai.hc.com.mysvgdemo.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import pailaidai.hc.com.mysvgdemo.R;

/**
 * Created by Administrator on 2018/5/4.
 */

public class MyProgress extends Dialog {
    public MyProgress(Context context) {
        super(context);
    }

    public MyProgress(Context context, int theme) {
        super(context, theme);
    }
//    /**
//     * 当窗口焦点改变时调用
//     */
//    public void onWindowFocusChanged(boolean hasFocus) {
//        ImageView imageView = (ImageView) findViewById(R.id.spinnerImageView);
//        // 获取ImageView上的动画背景
////        AnimationDrawable spinner = (AnimationDrawable) imageView.getBackground();
//        // 开始动画
//        RotateAnimation rotate  = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//        LinearInterpolator lin = new LinearInterpolator();
//        rotate.setInterpolator(lin);
//        rotate.setDuration(1500);//设置动画持续时间
//        rotate.setRepeatCount(-1);//设置重复次数
//        rotate.setFillAfter(true);//动画执行完后是否停留在执行完的状态
//        rotate.setStartOffset(10);//执行前的等待时间
//        imageView.setAnimation(rotate);
//        rotate.start();
////        spinner.start();
//    }
    /**
     * 弹出自定义ProgressDialog
     *
     * @param context
     *            上下文
     * @param message
     *            提示
     * @param cancelable
     *            是否按返回键取消
     * @param cancelListener
     *            按下返回键监听
     * @return
     */
    public static MyProgress createDialog(Context context, CharSequence message, boolean cancelable, OnCancelListener cancelListener) {
        MyProgress dialog = new MyProgress(context, R.style.Custom_Progress);
        dialog.setTitle("");
        dialog.setContentView(R.layout.z_customprogress_layout);
        if (message == null || message.length() == 0) {
            dialog.findViewById(R.id.dialogloading_text).setVisibility(View.GONE);
        } else {
            TextView txt = (TextView) dialog.findViewById(R.id.dialogloading_text);
            txt.setText(message);
        }
        // 按返回键是否取消
        dialog.setCancelable(cancelable);
        dialog.setCanceledOnTouchOutside(cancelable);
        // 监听返回键处理
        dialog.setOnCancelListener(cancelListener);
        // 设置居中
//        dialog.getWindow().getAttributes().gravity = Gravity.CENTER;
//        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
//        // 设置背景层透明度
//        lp.dimAmount = 0.2f;
//        dialog.getWindow().setAttributes(lp);
        return dialog;
    }

}
